<template>
  <div class="singerlist">
    <div class="singerinfo" v-for="item in artists" :key="item.id" @click=" toSingerDetail(item.id)">
      <img :src="item.img1v1Url" />
      <div class="name">
        <span>{{item.name }}</span>
        <span> ({{ item.alias[0] }})</span>
      </div>
    </div>
  </div>
</template>

<script>
import { getCloudSearch } from '../../network/search.js'
export default {
  props: ['type', 'value'],
  data () {
    return {
      artists: [],
      singerCount: 0
    }
  },
  methods: {
    toSingerDetail (id) {
      this.$router.push('/singer_detail/' + id)
    },
    getCloudSearch (type, keywords) {
      getCloudSearch(type, keywords).then(res => {
        // console.log(res.data)
        this.artists = res.data.result.artists
        this.singerCount = res.data.result.artistCount
        this.$emit('singerCount', this.singerCount + ' 首歌手')
        console.log(this.artists)
      })
    }
  },
  created () {
    this.getCloudSearch(this.type, this.value)
  },
  watch: {
    value (newVal, oldVal) {
      // console.log('新关键词:' + newVal)
      this.value = newVal
      this.getCloudSearch(this.type, this.value)
    }
  }
}
</script>

<style lang="less" scoped>
  .singerinfo {
    width: 100%;
    padding: 10px;
    display: flex;
    flex-direction: row;
    img {
      width: 75px;
      height: 75px;
      border-radius: 5px;
      margin-right: 15px;
    }
    .name {
      display: flex;
      align-items: center;
      span:last-child {
        margin-left: 2px;
        color: #b4b4b4;
      }
    }
  }
  .singerinfo:nth-child(2n) {
    background-color: #f9f9f9;
  }
  .singerinfo:hover {
    background-color: #f0f1f2;
  }
</style>
